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++)
54 : new VirtualPort(ports[i]);
55 ship.addBenkoBox(name, this);
58 public void addDestination(String dest) {
59 Destination[] newports = new Destination[ports.length+1];
60 System.arraycopy(ports, 0, newports, 0, ports.length);
61 newports[newports.length-1] = new VirtualPort(dest);
65 public class VirtualPort extends Destination {
67 public VirtualPort(String name) { this.name = name; }
68 public String getDestinationName() { return name; }
69 public Ship getShip() { return SlipwayBenkoBox.this.getShip(); }
70 public void addDataFromFabric(long data) { SlipwayBenkoBox.this.addDataFromFabric(name, (int)data); }
71 public String toString() { return getShip()+"."+getName(); }
73 public long addr = (default_addr++);
76 /** adds one token to the port from the switch fabric side */
77 void addTokenFromFabric() { addDataFromFabric(0); }
79 /** adds the included datum to the port from the switch fabric side */
80 void addDataFromFabric(int datum) { throw new RuntimeException("this should never happen!"); }
81 void addDataFromFabric(String name, int datum) {
82 addDataFromFabric(datum);
85 /** adds one token to the port from the ship side */
86 public void addTokenFromShip() { addDataFromShip(0); }
88 /** adds the included datum to the port from the switch fabric side */
89 public void addDataFromShip(int datum) { throw new RuntimeException("this should never happen!"); }
91 public Ship getShip() { return ship; }
93 public Fleet getFleet() { return getShip().getFleet(); }
95 public String toString() { return ship+"."+name; }
97 public String getName() { return name; }
99 public int getInstructionFifoLength() { return 4; }