1 package edu.berkeley.fleet.slipway;
2 import edu.berkeley.fleet.api.*;
3 import edu.berkeley.fleet.api.BenkoBox;
6 /** anything that has a destination address on the switch fabric */
7 public class SlipwayBenkoBox extends BenkoBox {
9 private final String name;
10 private final SlipwayShip ship;
11 private Destination[] ports;
13 public Iterable<Destination> getDestinations() {
14 ArrayList<Destination> ret = new ArrayList<Destination>();
15 for(Destination d : ports) ret.add(d);
18 private static int default_addr;
19 private static int default_instr_addr;
22 public int addr = (default_addr++);
23 public int instr_bits;
24 public int instr_addr = (default_instr_addr++);
25 protected boolean special = false;
26 protected boolean ihorn = false;
27 protected boolean dhorn = false;
29 public boolean special() { return special; }
30 public boolean ihorn() { return ihorn; }
31 public boolean dhorn() { return dhorn; }
33 public boolean isInbox() { return inbox; }
34 public boolean isOutbox() { return !inbox; }
35 public SlipwayBenkoBox(boolean inbox, SlipwayShip ship, String name) {
36 this(inbox, ship, name, false, false, false);
38 public SlipwayBenkoBox(boolean inbox, SlipwayShip ship, String name, boolean special) {
39 this(inbox, ship, name, special, false, false);
41 public SlipwayBenkoBox(boolean inbox, SlipwayShip ship, String name, boolean special, boolean ihorn, boolean dhorn) {
43 this.special = special;
48 String[] ports = new String[] { "" };
49 this.ports = new Destination[ports.length];
50 for(int i=0; i<ports.length; i++)
51 this.ports[i] = new VirtualPort(ports[i]);
52 ship.addBenkoBox(name, this);
55 public void addDestination(String dest) {
56 Destination[] newports = new Destination[ports.length+1];
57 System.arraycopy(ports, 0, newports, 0, ports.length);
58 newports[newports.length-1] = new VirtualPort(dest);
62 public class VirtualPort extends Destination {
64 public VirtualPort(String name) { this.name = name; }
65 public String getDestinationName() { return name; }
66 public Ship getShip() { return SlipwayBenkoBox.this.getShip(); }
67 public void addDataFromFabric(long data) { SlipwayBenkoBox.this.addDataFromFabric(name, (int)data); }
68 public String toString() { return getShip()+"."+getName(); }
70 public long addr = (default_addr++);
73 /** adds one token to the port from the switch fabric side */
74 void addTokenFromFabric() { addDataFromFabric(0); }
76 /** adds the included datum to the port from the switch fabric side */
77 void addDataFromFabric(int datum) { throw new RuntimeException("this should never happen!"); }
78 void addDataFromFabric(String name, int datum) {
79 addDataFromFabric(datum);
82 /** adds one token to the port from the ship side */
83 public void addTokenFromShip() { addDataFromShip(0); }
85 /** adds the included datum to the port from the switch fabric side */
86 public void addDataFromShip(int datum) { throw new RuntimeException("this should never happen!"); }
88 public Ship getShip() { return ship; }
90 public Fleet getFleet() { return getShip().getFleet(); }
92 public String toString() { return ship+"."+name; }
94 public String getName() { return name; }
96 public int getInstructionFifoLength() { return 4; }